package com.my.chapter9;

public class practice19 {
    public static void playGame(GameFactory factory){
        Game s = factory.getGame();
        s.move();
    }

    public static void main(String[] args) {
        playGame(new CoinFactory());
        playGame(new DiceFactory());
    }
}

interface Game{
    void move();
}

interface GameFactory{
    Game getGame();
}

class Coin implements Game{

    @Override
    public void move() {
        System.out.println("抛硬币");
    }
}

class CoinFactory implements GameFactory{

    @Override
    public Game getGame() {
        return new Coin();
    }
}

class Dice implements Game{

    @Override
    public void move() {
        System.out.println("掷骰子");
    }
}

class DiceFactory implements GameFactory{

    @Override
    public Game getGame() {
        return new Dice();
    }
}


